package com.chens.common.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Web配置类
 * @description 用于配置Web应用的相关设置，如静态资源处理
 * @author chenshun
 * @date 2023/08/10 16:22
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private FileStorageProperties fileStorageProperties;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 假设上传目录配置在 FileStorageProperties 中
        String uploadDir = fileStorageProperties.getUploadDir();
        // 将 /uploads/** 映射到实际的文件存储目录
        registry.addResourceHandler("/api/uploads/**")
                .addResourceLocations("file:" + uploadDir + "/");
    }
}
